<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('项目信息列表')" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="gray-bg">
<div class="ui-layout-west">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-grid"></i> 选择区划
            </div>
        </div>
        <div class="ui-layout-content">
            <div id="tree" class="ztree"></div>
        </div>
    </div>
</div>

<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <input type="hidden" name="geocode" id="geocode"/>
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>项目类型：</p>
                                <select name="projectType" th:with="type=${@dict.getType('sys_project_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li class="select-time">
                                <p>开始时间：</p>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginBeginTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endBeginTime]"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="projectAdd()" shiro:hasPermission="system:project:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:project:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:project:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>

<th:block th:include="include :: footer" />
<th:block th:include="include :: layout-latest-js" />
<th:block th:include="include :: ztree-js" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:project:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:project:remove')}]];
    var projectTypeDatas = [[${@dict.getType('sys_project_type')}]];
    var prefix = ctx + "system/project";
    //一开始执行的js
    $(function() {
        var panehHidden = false;
        if ($(this).width() < 769) {
            panehHidden = true;
        }
        $('body').layout({ initClosed: panehHidden, west__size: 205 });
        queryProjectList();
        queryDeptTree();
    });

    function queryProjectList() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add?{id}",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "项目信息",
            columns: [{
                checkbox: true
            },
                {
                    field : 'projectId',
                    title : 'null',
                    visible: false
                },
                {
                    field : 'projectName',
                    title : '项目名称',
                    align: 'center'
                },
                {
                    field : 'projectType',
                    title : '项目类型',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(projectTypeDatas, value);
                    }
                },
                {
                    field : 'beginTime',
                    title : '开始时间',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return changeDateFormat(value);
                    }
                },
                {
                    field : 'workload',
                    title : '使用工作量',
                    align: 'center'
                },
                {
                    field : 'endTime',
                    title : '项目状态',
                    align: 'center',
                    formatter: function(value, row, index) {
                        if(value == null){
                            return '执行中';
                        }else{
                            return '已结束';
                        }
                    }
                }]
        };
        $.table.init(options);
    }

    function queryDeptTree()
    {
        var url = ctx + "geocode/projectTreeData";
        var options = {
            url: url,
            expandLevel: 1,
            onClick : zOnClick
        };
        $.tree.init(options);

        function zOnClick(event, treeId, treeNode) {
            $("#geocode").val(treeNode.id);
            $.table.search();
        }
    }

    function projectAdd(){
        if($("#geocode").val() == '' || $("#geocode").val().length < 6){
            $.modal.alertWarning("请在左侧选择省份！");
        }else{
            var params = "geocode=" + $("#geocode").val();
            $.operate.add(params);
        }
    }

    //转换日期格式(时间戳转换为datetime格式)
    function changeDateFormat(cellval) {
        if (cellval != null) {
            var date = new Date(cellval);
            var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
            var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();

            var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
            var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
            var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();

            return date.getFullYear()+"-"+month + "-" + currentDate ;
        }
    }
</script>
</body>
</html>